<?php
class SectorsController extends AppController {

	var $name = 'Sectors';
	var $helpers 	= array('Javascript','Ajax'); 
	var $components = array('RequestHandler');
	var $uses = array("User","Grupo","Iglesia","Tipogrupo","Rol","Tiporol","Config","Oficio","Sector");
	
	function loadSectoresByComuna(){
		$response = array(
				"response"=>array(
					"error"=>true,
					"showErrorThread"=>false,
					"title"=>"Identificador Inválido",
					"mensaje"=>"El identificador de comuna no es válido."
				)
			);
		if(!empty($_POST["id"]) && intval($_POST["id"])>0 ):
			$comunaId = $_POST["id"];
			$sectores = $this->Sector->find('all',array(
								'conditions'=>array(
									"Sector.comuna_id"=>$comunaId
								),
								'recursive' => -1
							)
				);
			$response = array(
				"response"=>array(
					"error"=>false,
					"errorThread"=>"",
					"errorTitle"=>"",
					"showErrorThread"=>false,
					"type"=>"list", 
					"data"=>$sectores,
					"title"=>"Sectores"
				)
			);
		endif;	
		$this->outJson($response);
	}
}
?>